﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace Server
{
    /// <summary>
    /// 工具类
    /// </summary>
    public class Tools
    {
        /// <summary>
        /// 向目标传输机台发送消息 
        /// </summary>
        /// <param name="LocalPort"></param>
        /// <param name="DeviceIP"></param>
        /// <param name="DeivcePort"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static Task 向传输机台发送指令(int LocalPort, string DeviceIP, int DeivcePort, byte[] data)
        {
            try
            {
                IPEndPoint local = new IPEndPoint(IPAddress.Parse("127.0.0.1"), LocalPort); //本地发送，注意多网卡模式
                UdpClient udpClient = new UdpClient(local);
                IPEndPoint iPEndPoint = new IPEndPoint(IPAddress.Parse(DeviceIP), DeivcePort); //目标 
                udpClient.Send(data, data.Length, iPEndPoint);
                udpClient.Close();
            }
            catch
            {

            }
            return Task.CompletedTask;
        }


        /// <summary>
        /// 向AGV发送消息
        /// </summary>
        /// <param name="IP"></param>
        /// <param name="Port"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static Task 向AGV发送指令(string IP, int Port, byte[] data, int localPort = 5000)
        {
            try
            {
                UdpClient udpClient = new UdpClient(localPort); //约定的发送端口
                IPEndPoint iPEndPoint = new IPEndPoint(IPAddress.Parse(IP), Port); //目标 
                udpClient.Send(data, data.Length, iPEndPoint);
                udpClient.Close();
            }
            catch
            {

            }
            return Task.CompletedTask;
        }


        
    } 


    public class 常量
    {
        /// <summary>
        /// 90度对应的弧度值
        /// </summary>
        public static readonly float 弧度90 = 1.571f;

        /// <summary>
        /// AGV半径(50cm)
        /// </summary>
        public static readonly float 旋转半径 = 50F;

        /// <summary>
        /// 与前面AGV的距离（单位cm） ,前端到下一辆屁股
        /// </summary>
        public static readonly float 物体间距 = 100F;


        public static readonly int Agv接收端口 = 5000;
    }
}
